package priv.conceit.sc.hoxton.auth.authority.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import priv.conceit.sc.hoxton.auth.authority.service.UserService;
import priv.conceit.sc.hoxton.common.entity.auth.authority.dto.CurrentUserInfoDTO;
import priv.conceit.sc.hoxton.common.entity.auth.authority.qo.UserLoginQO;
import priv.conceit.sc.hoxton.common.web.WebResponse;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.io.FileNotFoundException;

/**
 * <p>
 * 用户 前端控制器
 * </p>
 *
 * @author conceit
 * @since 2020-11-20
 */
@RestController
@RequestMapping("/authority/user")
public class UserController {

	@Autowired
	private UserService userService;

	/**
	 * login 用户统一登陆地址
	 *
	 * @param userLoginQO
	 * @return priv.conceit.sc.hoxton.common.web.WebResponse
	 * @author conceit
	 * @date 2020/11/3 16:22
	 */
	@PostMapping("login")
	public WebResponse<CurrentUserInfoDTO> login(@Valid @RequestBody UserLoginQO userLoginQO){
		return WebResponse.build(userService.login(userLoginQO));
	}

	/**
	 * tokenVerify  验证token,并返回用户认证信息
	 *
	 * @param token
	 * @return priv.conceit.sc.hoxton.common.web.WebResponse
	 * @author conceit
	 * @date 2020/11/3 16:29
	 */
	@GetMapping("/token/verify/{token}")
	public WebResponse tokenVerify(@NotBlank @PathVariable String token) throws FileNotFoundException {
		//throw new FileNotFoundException("SS");
		return WebResponse.build(userService.tokenVerify(token));
	}


}

